// 格式化时间
const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('-')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

// 字符串转毫秒时间
const getUnixTime = (dateStr) => {
  var newstr = dateStr.replace(/-/g,'/'); 
  var date =  new Date(newstr); 
  var time_str = date.getTime().toString();
  return time_str.substr(0, 10);
}

/*获取当前页url*/
const getCurrentPageUrl=()=>{
  let pages = getCurrentPages()    //获取加载的页面
  let currentPage = pages[pages.length-1]    //获取当前页面的对象
  let url = currentPage.route    //当前页面url
  return url
}
/*获取当前页参数*/
const getCurrentPageParam=()=>{
  let pages = getCurrentPages()    //获取加载的页面
  let currentPage = pages[pages.length-1]    //获取当前页面的对象
  let options = currentPage.options    //如果要获取url中所带的参数可以查看options
  return options
}
module.exports = {
  formatTime,
  getUnixTime,
  getCurrentPageUrl,
  getCurrentPageParam
}
